package example.controller;

import example.entity.Goods;
import example.entity.Goodstype;
import example.entity.Orderdetail;
import example.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
public class orderCtrl {
    @Resource
    OrderService orderService;

    @RequestMapping(value = "/orders")
    public String getGoodsTypesList(Model model) {
        List<Goods> orders = orderService.findall();
        List<Orderdetail> orderdetails = orderService.finddall();
        System.out.println(orders.size());
        System.out.println(orders.get(0).getGdid());
        model.addAttribute("orders", orders);
        model.addAttribute("orderdetails", orderdetails);

        return "orders";
    }


    @GetMapping("delorders/{id}")
    public String delGoods(@PathVariable("id") int id , Model model) {
        int num = orderService.deleteById(id);
        model.addAttribute("msg","删除成功！");
        return  "forward:/orders";

    }
}
